package com.kotlin.heimaplayer.presenter.impl

import com.kotlin.heimaplayer.base.BaseListPresenter
import com.kotlin.heimaplayer.model.CommonResultBean
import com.kotlin.heimaplayer.model.WyMvBean
import com.kotlin.heimaplayer.net.MvListRequest
import com.kotlin.heimaplayer.net.ResponseHandler
import com.kotlin.heimaplayer.presenter.interf.MvListPresenter
import com.kotlin.heimaplayer.view.MvListView

class MvListPresenterImpl(var name:String, var mvListView: MvListView?): MvListPresenter,
    ResponseHandler<CommonResultBean<WyMvBean>> {
    override fun onError(type: Int, msg: String?) {
        mvListView?.onError(msg)
    }

    override fun onSuccess(type: Int, result: CommonResultBean<WyMvBean>) {
        when(type){
            BaseListPresenter.TYPE_INIT_OR_REFRESH->mvListView?.loadSuccess(result.data.videos)
            BaseListPresenter.TYPE_LOAD_MORE->mvListView?.loadMore(result.data.videos)
        }
    }

    override fun loadDatas() {
        MvListRequest(BaseListPresenter.TYPE_INIT_OR_REFRESH,1,name,this).excute()
    }

    override fun loadMore(page: Int) {
        MvListRequest(BaseListPresenter.TYPE_LOAD_MORE,page,name,this).excute()
    }

    override fun destoryView() {
        if(mvListView != null){
            mvListView = null
        }
    }
}